﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TruongVuWebsite.Admin
{
    public partial class ProductManagement : System.Web.UI.Page
    {
        private TruongVu.Business.ServiceModel _serviceModel = new TruongVu.Business.ServiceModel();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.ProductGridView.DataSource = this._serviceModel.GetAll();
            this.ProductGridView.DataBind();
        }

        protected void ProductGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            List<TruongVu.Data.Service> services = this.ProductGridView.DataSource as List<TruongVu.Data.Service>;
            if (services != null && services.Count > e.RowIndex)
            {
                this._serviceModel.Delete(services[e.RowIndex].ID);
                services.RemoveAt(e.RowIndex);
                this.ProductGridView.DataBind();
            }
        }

        protected void ProductGridView_RowEditing(object sender, GridViewEditEventArgs e)
        {
            List<TruongVu.Data.Service> services = this.ProductGridView.DataSource as List<TruongVu.Data.Service>;
            if (services != null && services.Count > e.NewEditIndex)
            {
                Response.Redirect("Product.aspx?ID=" + services[e.NewEditIndex].ID);
            }
            else
            {
                e.Cancel = true;
            }
        }
    }
}